package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Pazsalvo;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class PazsalvoPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Pazsalvo> list;

public PazsalvoPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Pazsalvo pazsalvo ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into pazsalvo(IDPAZSALVO,IDRECIBO,ID,TIPOID,FECHAPAZSALVO,FECHAVALIDO,IDMUNICIPIO,ACTIVO,USERNAME,FECHA)  values(?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setLong(1,pazsalvo.getIDPAZSALVO());
        pinsert.setInt(2,pazsalvo.getIDRECIBO());
        pinsert.setString(3,pazsalvo.getID());
        pinsert.setString(4,pazsalvo.getTIPOID());
        pinsert.setDate(5,pazsalvo.getFECHAPAZSALVO());
        pinsert.setDate(6,pazsalvo.getFECHAVALIDO());
        pinsert.setString(7,pazsalvo.getIDMUNICIPIO());
        pinsert.setString(8,pazsalvo.getACTIVO());
        pinsert.setString(9,pazsalvo.getUSERNAME());
        pinsert.setDate(10,pazsalvo.getFECHA());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Pazsalvo pazsalvo ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update pazsalvo set  IDPAZSALVO=?, IDRECIBO=?, ID=?, TIPOID=?, FECHAPAZSALVO=?, FECHAVALIDO=?, IDMUNICIPIO=?, ACTIVO=?, USERNAME=?, FECHA=?  where  IDPAZSALVO ='"+pazsalvo.getIDPAZSALVO()+"' and  IDMUNICIPIO ='"+pazsalvo.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,pazsalvo.getIDPAZSALVO());
pupdate.setInt(2,pazsalvo.getIDRECIBO());
pupdate.setString(3,pazsalvo.getID());
pupdate.setString(4,pazsalvo.getTIPOID());
pupdate.setDate(5,pazsalvo.getFECHAPAZSALVO());
pupdate.setDate(6,pazsalvo.getFECHAVALIDO());
pupdate.setString(7,pazsalvo.getIDMUNICIPIO());
pupdate.setString(8,pazsalvo.getACTIVO());
pupdate.setString(9,pazsalvo.getUSERNAME());
pupdate.setDate(10,pazsalvo.getFECHA());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  pazsalvo set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Pazsalvo pazsalvo_old , Pazsalvo pazsalvo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update pazsalvo set  IDPAZSALVO=? ,  IDMUNICIPIO=?  where  IDPAZSALVO ='"+pazsalvo_old.getIDPAZSALVO()+"' and  IDMUNICIPIO ='"+pazsalvo_old.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,pazsalvo.getIDPAZSALVO());pupdate.setString(7,pazsalvo.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Pazsalvo pazsalvo ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from pazsalvo  where  IDPAZSALVO = ? and  IDMUNICIPIO = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setLong(1,pazsalvo.getIDPAZSALVO());
pdelete.setString(7,pazsalvo.getIDMUNICIPIO());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from pazsalvo where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from pazsalvo  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Pazsalvo pazsalvo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from pazsalvo where IDPAZSALVO='"+pazsalvo.getIDPAZSALVO()+"' and IDMUNICIPIO='"+pazsalvo.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Pazsalvo findByPrimaryKey(Pazsalvo pazsalvo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from pazsalvo where IDPAZSALVO='"+pazsalvo.getIDPAZSALVO()+"' and IDMUNICIPIO='"+pazsalvo.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            pazsalvo.setIDPAZSALVO(rs.getLong("IDPAZSALVO"));
pazsalvo.setIDRECIBO(rs.getInt("IDRECIBO"));
pazsalvo.setID(rs.getString("ID"));
pazsalvo.setTIPOID(rs.getString("TIPOID"));
pazsalvo.setFECHAPAZSALVO(rs.getDate("FECHAPAZSALVO"));
pazsalvo.setFECHAVALIDO(rs.getDate("FECHAVALIDO"));
pazsalvo.setIDMUNICIPIO(rs.getString("IDMUNICIPIO"));
pazsalvo.setACTIVO(rs.getString("ACTIVO"));
pazsalvo.setUSERNAME(rs.getString("USERNAME"));
pazsalvo.setFECHA(rs.getDate("FECHA"));
    }
    rs.close();
    psquery.close();
 return pazsalvo;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDPAZSALVO()
*/

public static List<Pazsalvo> findByIDPAZSALVO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where IDPAZSALVO='"+pazsalvo.getIDPAZSALVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDRECIBO()
*/

public static List<Pazsalvo> findByIDRECIBO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where IDRECIBO='"+pazsalvo.getIDRECIBO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByID()
*/

public static List<Pazsalvo> findByID(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where ID='"+pazsalvo.getID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTIPOID()
*/

public static List<Pazsalvo> findByTIPOID(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where TIPOID='"+pazsalvo.getTIPOID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHAPAZSALVO()
*/

public static List<Pazsalvo> findByFECHAPAZSALVO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where FECHAPAZSALVO='"+pazsalvo.getFECHAPAZSALVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHAVALIDO()
*/

public static List<Pazsalvo> findByFECHAVALIDO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where FECHAVALIDO='"+pazsalvo.getFECHAVALIDO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDMUNICIPIO()
*/

public static List<Pazsalvo> findByIDMUNICIPIO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where IDMUNICIPIO='"+pazsalvo.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByACTIVO()
*/

public static List<Pazsalvo> findByACTIVO(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where ACTIVO='"+pazsalvo.getACTIVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUSERNAME()
*/

public static List<Pazsalvo> findByUSERNAME(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where USERNAME='"+pazsalvo.getUSERNAME()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHA()
*/

public static List<Pazsalvo> findByFECHA(Pazsalvo pazsalvo,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
      String sql = "select * from pazsalvo where FECHA='"+pazsalvo.getFECHA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Pazsalvo> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Pazsalvo>();
  String sql = "select * from pazsalvo";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from pazsalvo";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from pazsalvo where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from pazsalvo";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from pazsalvo where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Pazsalvo> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Pazsalvo>();
  String sql = "select * from pazsalvo where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Pazsalvo> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Pazsalvo>();
  String sql = "select * from pazsalvo";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "pazsalvo" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Pazsalvo pazsalvo2 = new Pazsalvo(
         rs.getLong("IDPAZSALVO"),rs.getInt("IDRECIBO"),rs.getString("ID"),rs.getString("TIPOID"),rs.getDate("FECHAPAZSALVO"),rs.getDate("FECHAVALIDO"),rs.getString("IDMUNICIPIO"),rs.getString("ACTIVO"),rs.getString("USERNAME"),rs.getDate("FECHA"));
            
            
       list.add(pazsalvo2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
